package com.o2o.controller;

import com.o2o.entity.Area;
import com.o2o.service.AreaService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.*;

/**
 * package_name:com.o2o.controller
 * Author:徐亚远
 * Date:2019/11/27 15:46
 * 项目名:o2o
 * Desription:
 **/
@Controller
public class AreaController {
    org.slf4j.Logger logger = LoggerFactory.getLogger(AreaController.class);
    @Autowired
    private AreaService areaService;
    @RequestMapping("/area")
    @ResponseBody
    public String query(){
       List<Area> list =  areaService.queryAll();
       Iterator<Area> it = list.iterator();
       while (it.hasNext()){
           System.out.println(it.next());
       }
        return "success";
    }

    @RequestMapping(value = "/map",method = RequestMethod.GET)
    @ResponseBody
    private Map<String,Object> listArea(){
        logger.info("=====start=====");
        long startTime = System.currentTimeMillis();
        Map<String,Object> modelMap = new HashMap<>();
        List<Area> list = new ArrayList<Area>();
        try {
            list = areaService.queryAll();
            modelMap.put("rows",list );
            modelMap.put("total",list.size() );
        }catch (Exception e){
            e.printStackTrace();
            modelMap.put("success",false );
            modelMap.put("errMsg",e.toString() );
        }
        logger.error("test error");
        Long endTime = System.currentTimeMillis();
        logger.debug("costTime:[{}ms]",endTime-startTime);
        logger.info("======end====");
        return modelMap;
    }

}
